<%@ page language="java" pageEncoding="utf-8"%>
<%@taglib prefix="s" uri="/struts-tags"%>
<style type="text/css">
<!--
 *{padding:0;margin:0;font-size:14px;font-weight:normal;list-style:none;}
 #wrap{width:960px;margin:20px auto 0 auto;}
 a{color:#666;text-decoration:none;}
 h1{font-size:18px;padding:5px;text-decoration:underline;cursor:pointer;position:relative;}
 #tit{height:25px;background-color:#ff9900;position:relative;margin:1px 1px 0 1px;cursor:move;}
#closepop{position:absolute;top:3px;right:20px;cursor:pointer;color:#000;font-weight:bold;}
 h2{clear:both;font-weight:bold;font-size:14px;}
 body{padding:0;height:100%;line-height:150%;}
 #pop{position:absolute;width:600px;border:solid 1px #666;z-index:99;background-color:#fff;}
 
#opt h3{display:blcok;clear:both;padding-left:10px;}
.optcon{margin-left:30px;}
.optcon ul li,#spop ul li,#pop_con ul li{float:left;}
.optcon ul li a,#pop_con ul li a{padding:3px;margin-right:10px;cursor:pointer;}
.optcon ul li a:hover,#pop_con ul li a:hover,#spop ul li a:hover{color:#006699;background-color:#e0eeee;}
.seled,#pop_sele li a{background-color:#e0eeee;color:#990000;}
#spop{width:210px;height:120px;border:solid 1px #666;position:absolute;z-index:99;background-color:#fff;}
#spop ul li a{cursor:pointer;}
#spop ul li{width:70px;overflow:hidden;}
#overlay{width:100%;background-color:#666;position:absolute;top:0;left:0;opacity:0.2;z-index:98;filter:alpha(opacity=20);}
#popbody{padding:10px;}
-->
 </style>
<script type="text/javascript" src="${aier_js_url}j.js"></script>
<script type="text/javascript">
var select_count =8;//允许选择的最大城市数量。

TC = new Object();
TC.EventMonitor = function(){
    this.listeners = new Object();
}
TC.EventMonitor.prototype.broadcast=function(widgetObj, msg, data){
    var lst = this.listeners[msg];
    if(lst != null){
        for(var o in lst){
            lst[o](widgetObj, data);
        }
    }
}
TC.EventMonitor.prototype.subscribe=function(msg, callback){
    var lst = this.listeners[msg];
    if (lst) {
        lst.push(callback);
    } else {
        this.listeners[msg] = [callback];
    }
}
TC.EventMonitor.prototype.unsubscribe=function(msg, callback){
    var lst = this.listener[msg];
    if (lst != null){
        lst = lst.filter(function(ele, index, arr){return ele!=callback;});
    }
}
var event_monitor = new TC.EventMonitor();
function load_event_monitor(root) {
    var re = /a_(\w+)/;
    var fns = {};
    $(".j", root).each(function(i) {
        var m = re.exec(this.className);
        if (m) {
            var f = fns[m[1]];
            if (!f) {
                f = eval("TC.init_"+m[1]);
                fns[m[1]] = f;
            }
            f && f(this);
        }
    });
}
$(function() {
    load_event_monitor(document);
});

//工作地点键值匹配数组
var ja=[];
<s:iterator value="cb">ja['<s:property value="id"/>']='<s:property value="name"/>';</s:iterator>
//主要城市数据字典
var maincity=[['华北-东北',['0100','0500','2303','2302','2402','2202']],['华东 地区',['0200','0702','0703','0802','0803','1502','1102','1202','1203']],['华南-华中',['0302','0400','0308','1802','1902','1702']],['西北-西南',['2002','0902','0600','2502']]];
//所有省份数据字典
var allprov=[['华北-东北',['1600','2100','2800','2300','2400','2200']],['华东 地区',['0700','0800','1500','1100','1300','1200']],['华南-华中',['0300','1400','1000','1700','1800','1900']],['西北-西南',['2000','2700','3200','2900','3100','0900','2600','2500','3000']],['其它',['3300','3400','3500','3600']]];
//获取滚动条的高度
function getPageScroll(){
	var yScroll;
	if (self.pageYOffset) {
		yScroll = self.pageYOffset;
	} else if (document.documentElement && document.documentElement.scrollTop){	 // Explorer 6 Strict
		yScroll = document.documentElement.scrollTop;
	} else if (document.body) {// all other Explorers
		yScroll = document.body.scrollTop;
	}
	arrayPageScroll = new Array('',yScroll) 
	return arrayPageScroll;
}
//获取页面实际大小
function getPageSize(){ 
    
    var xScroll, yScroll; 
    
    if (window.innerHeight && window.scrollMaxY) {    
        xScroll = document.body.scrollWidth; 
        yScroll = window.innerHeight + window.scrollMaxY; 
    } else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac 
        xScroll = document.body.scrollWidth; 
        yScroll = document.body.scrollHeight; 
    } else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari 
        xScroll = document.body.offsetWidth; 
        yScroll = document.body.offsetHeight; 
    } 
    
    var windowWidth, windowHeight; 
    if (self.innerHeight) {    // all except Explorer 
        windowWidth = self.innerWidth; 
        windowHeight = self.innerHeight; 
    } else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode 
        windowWidth = document.documentElement.clientWidth; 
        windowHeight = document.documentElement.clientHeight; 
    } else if (document.body) { // other Explorers 
        windowWidth = document.body.clientWidth; 
        windowHeight = document.body.clientHeight; 
    }    
    
    // for small pages with total height less then height of the viewport 
    if(yScroll < windowHeight){ 
        pageHeight = windowHeight; 
    } else {  
        pageHeight = yScroll; 
    } 
  
    // for small pages with total width less then width of the viewport 
    if(xScroll < windowWidth){    
        pageWidth = windowWidth; 
    } else { 
        pageWidth = xScroll; 
    } 
  
    arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight); 
    return arrayPageSize; 
}

TC.init_del_sele=function(o)
{
	$(o).click(function(){
		var id=$(o).attr('id').split('-')[1];
		event_monitor.broadcast(this, "sele_deled", id);
	});
}
TC.init_sele_city=function(o)
{
	$(o).click(function(){
		var id=$(o).attr('id').split('-')[1];
		if($(o).hasClass("seled")){event_monitor.broadcast(this, "sele_deled", id);return;}
		var sel_arr=$('#sv').val().split(' ');
		if(sel_arr.length == select_count+1){alert('您只能选择'+select_count+"个城市。");return;}
		if($('#se-'+id).length==0)
		{
			$('#pop_sele').html($('#pop_sele').html()+"<li><a class='j a_del_sele' id='se-"+id+"' href='javascript:void(0);'>"+$(o).html()+"</a></li>");
			load_event_monitor($('#pop_sele'));
			event_monitor.broadcast(this, "sele_add", id);
			$('#c-'+id).addClass('seled');
			if($('#pc-'+id).length!=0){$('#pc-'+id).addClass('seled');};
		}
	});
}
TC.init_sh_city=function(o)
{
	$(o).click(function(e){
		var obj = $(o).attr('id').split('-')[1];
		var id=obj.substring(0,2);
		var content='<ul>';
		var key;
		for(var i=0;i<20;i++)
		{
			if(i<10) key=id+'0'+i;else key=id+i+'';
			if(ja[key])
			{
				if($('#se-'+key).length==0)
					content+="<li><a href='javascript:void(0);' id='pc-"+key+"' class='j a_sele_city'>"+ja[key]+"</a></li>";
				else
					content+="<li><a href='javascript:void(0);' id='pc-"+key+"' class='j a_sele_city seled'>"+ja[key]+"</a></li>";
			}
		}
		content+='</ul>';
		var px = e.pageX-15;
		var py = e.pageY-15;
		$("#spop").html(content).css('top',py+'px').css('left',px+'px').show();
		load_event_monitor($('#spop'));
	});
}
function getValue(data){var val='';var selvalue = data.split(' ');	for(i=0;i<selvalue.length-1;i++){val+=ja[selvalue[i]+''] + ' ';}return val;};

var isbuild=false;
var ismd=false;
var lmX=0;
var lmY=0;
var leX=0;
var leY=0;
$(function(){
	$("#sub_form").click(function(){
	var se = getValue($("#sv").val());alert('您选择了：'+se+', id: ' + $("#sv").val());  
	});  

	if(!isbuild) {
	var content = '<h2>主要城市</h2>';
		for(var i=0;i<maincity.length;i++)
		{
			content +='<h3>' +maincity[i][0]+"</h3><div class='optcon'><ul>";
			for(var k=0;k<maincity[i][1].length;k++)
			{
			content+="<li><a class='j a_sele_city' id='c-"+maincity[i][1][k]+"' href='javascript:void(0);'>"+ja[maincity[i][1][k]]+"</a></li>";
			}
			content+='</ul></div>';
		}
		
		content +="<h2>所有省份</h2>";
		for(var i=0;i<allprov.length;i++)
		{
			content+='<h3>'+allprov[i][0]+"</h3><div class='optcon'><ul>";
			for(var k=0;k<allprov[i][1].length;k++){content+="<li><a class='j a_sh_city' id='p-"+allprov[i][1][k]+"' href='javascript:void(0);'>"+ja[allprov[i][1][k]]+"</a></li>";}
			content+="</ul></div>";
		}
		$('#opt').html(content);
		load_event_monitor($('#opt'));
		isbuild = true;
	}

	$("#sh").click(function(){ 
		var arrayPageSize = getPageSize();
		var arrayPageScroll = getPageScroll();
		$('#pop').css('top',(arrayPageScroll[1] + ((arrayPageSize[3] - 35 - 400) / 2) + 'px')).css('left',(((arrayPageSize[0] - 20 - 600) / 2) + 'px')).show(); 
		var h=arrayPageSize[1] + 35;
		$('#overlay').css('height',(h+'px')).show();
	}); 

	event_monitor.subscribe("sele_deled",function(o,data){
			$('#c-'+data).removeClass('seled');
			if($('#pc-'+data).length!=0){$('#pc-'+data).removeClass('seled');}
			//$('#c-'+data).each(function(i,obj){obj.removeClass('seled');});  
			$('#sv').val($('#sv').val().replace(data+' ',''));
			$('#mycity').html(getValue($('#sv').val()));
			$('#se-'+data).remove();
	   });
	  event_monitor.subscribe("sele_add",function(o,data){
			var cv=$('#sv').val();	
			if(cv.lastIndexOf(data)<0 && ja[data])
			{
				$('#sv').val($('#sv').val()+data+' ');
				$('#mycity').html(getValue($('#sv').val()));
			}
			if(data.substring(2)=='00'){var key='';for(var i=1;i<20;i++){
				if(i<10) key=data.substring(0,2)+'0'+i;else key=data.substring(0,2)+i;
				event_monitor.broadcast(null, "sele_deled", key);}
				}
			else{event_monitor.broadcast(null, "sele_deled", data.substring(0,2)+'00');}
	   });

	  $('#pop').mouseover(function(){$('#spop').hide();});

	  $('#closepop').click(function(){$('#pop').hide();$('#overlay').hide();});

	  $('#tit').mousedown(function(e){
			if(leX==0)
			{
				leX=parseInt($('#pop').css('left').replace('px',''));
				leY=parseInt($('#pop').css('top').replace('px',''));
			}
			lmX = e.pageX;lmY=e.pageY;ismd=true;
			return false;
	  }).mouseup(function(e){ if(ismd){upPosition(e.pageX,e.pageY);ismd=false;} });

	  $(document).mousemove(function(e){if(ismd)
	  {upPosition(e.pageX,e.pageY);return false;}}).mouseup(function(e){ 	if(ismd){upPosition(e.pageX,e.pageY);ismd=false;} 		});
	  
});
 
function upPosition(x,y){ 
leX=parseInt(x-lmX+leX);
leY=parseInt(y-lmY+leY);

$('#pop').css('left',(leX+'px')).css('top',(leY+'px')); 
lmX=x;lmY=y;
}

</script>

<div id="wrap">
<h1 id="sh">选择城市  </h1>
<strong style="font-weight: bold;">已经选定的城市</strong>: <div id="mycity">天津市 武汉市 重庆市 保定市 </div>
<div id="sele_con">
</div>
<div id="cmd">
<div id="test"></div>
<hr style="border-style: none solid solid; border-color: -moz-use-text-color rgb(153, 0, 0) rgb(153, 0, 0); border-width: medium 1px 1px;">
	<input value="0500 1802 0600 1604 " id="sv" type="hidden">
</div>
</div>
<div id="pop" style="top: 84px; left: 202px; display: none;">
	<div id="tit"><span id="closepop">[ 关闭 ]</span></div>
	<div id="popbody">
	<span style="font-size: 16px; color: rgb(153, 0, 0); font-weight: bold;">已选择城市：</span>
		<div id="pop_con">
			<ul id="pop_sele"><li><a class="j a_del_sele" id="se-0500" href="javascript:void(0);">天津市</a></li><li><a class="j a_del_sele" id="se-1802" href="javascript:void(0);">武汉市</a></li><li><a class="j a_del_sele" id="se-0600" href="javascript:void(0);">重庆市</a></li><li><a class="j a_del_sele" id="se-1604" href="javascript:void(0);">保定市</a></li></ul> 
			<div id="opt"><h2>主要城市</h2><h3>华北-东北</h3><div class="optcon"><ul><li><a class="j a_sele_city" id="c-0100" href="javascript:void(0);">北京市</a></li><li><a class="j a_sele_city seled" id="c-0500" href="javascript:void(0);">天津市</a></li><li><a class="j a_sele_city" id="c-2303" href="javascript:void(0);">大连市</a></li><li><a class="j a_sele_city" id="c-2302" href="javascript:void(0);">沈阳市</a></li><li><a class="j a_sele_city" id="c-2402" href="javascript:void(0);">长春市</a></li><li><a class="j a_sele_city" id="c-2202" href="javascript:void(0);">哈尔滨市</a></li></ul></div><h3>华东 地区</h3><div class="optcon"><ul><li><a class="j a_sele_city" id="c-0200" href="javascript:void(0);">上海市</a></li><li><a class="j a_sele_city" id="c-0702" href="javascript:void(0);">南京市</a></li><li><a class="j a_sele_city" id="c-0703" href="javascript:void(0);">苏州市</a></li><li><a class="j a_sele_city" id="c-0802" href="javascript:void(0);">杭州市</a></li><li><a class="j a_sele_city" id="c-0803" href="javascript:void(0);">宁波市</a></li><li><a class="j a_sele_city" id="c-1502" href="javascript:void(0);">合肥市</a></li><li><a class="j a_sele_city" id="c-1102" href="javascript:void(0);">福州市</a></li><li><a class="j a_sele_city" id="c-1202" href="javascript:void(0);">济南市</a></li><li><a class="j a_sele_city" id="c-1203" href="javascript:void(0);">青岛市</a></li></ul></div><h3>华南-华中</h3><div class="optcon"><ul><li><a class="j a_sele_city" id="c-0302" href="javascript:void(0);">广州市</a></li><li><a class="j a_sele_city" id="c-0400" href="javascript:void(0);">深圳市</a></li><li><a class="j a_sele_city" id="c-0308" href="javascript:void(0);">东莞市</a></li><li><a class="j a_sele_city seled" id="c-1802" href="javascript:void(0);">武汉市</a></li><li><a class="j a_sele_city" id="c-1902" href="javascript:void(0);">长沙市</a></li><li><a class="j a_sele_city" id="c-1702" href="javascript:void(0);">郑州市</a></li></ul></div><h3>西北-西南</h3><div class="optcon"><ul><li><a class="j a_sele_city" id="c-2002" href="javascript:void(0);">西安市</a></li><li><a class="j a_sele_city" id="c-0902" href="javascript:void(0);">成都市</a></li><li><a class="j a_sele_city seled" id="c-0600" href="javascript:void(0);">重庆市</a></li><li><a class="j a_sele_city" id="c-2502" href="javascript:void(0);">昆明市</a></li></ul></div><h2>所有省份</h2><h3>华北-东北</h3><div class="optcon"><ul><li><a class="j a_sh_city" id="p-1600" href="javascript:void(0);">河北省</a></li><li><a class="j a_sh_city" id="p-2100" href="javascript:void(0);">山西省</a></li><li><a class="j a_sh_city" id="p-2800" href="javascript:void(0);">内蒙古</a></li><li><a class="j a_sh_city" id="p-2300" href="javascript:void(0);">辽宁省</a></li><li><a class="j a_sh_city" id="p-2400" href="javascript:void(0);">吉林省</a></li><li><a class="j a_sh_city" id="p-2200" href="javascript:void(0);">黑龙江省</a></li></ul></div><h3>华东 地区</h3><div class="optcon"><ul><li><a class="j a_sh_city" id="p-0700" href="javascript:void(0);">江苏省</a></li><li><a class="j a_sh_city" id="p-0800" href="javascript:void(0);">浙江省</a></li><li><a class="j a_sh_city" id="p-1500" href="javascript:void(0);">安徽省</a></li><li><a class="j a_sh_city" id="p-1100" href="javascript:void(0);">福建省</a></li><li><a class="j a_sh_city" id="p-1300" href="javascript:void(0);">江西省</a></li><li><a class="j a_sh_city" id="p-1200" href="javascript:void(0);">山东省</a></li></ul></div><h3>华南-华中</h3><div class="optcon"><ul><li><a class="j a_sh_city" id="p-0300" href="javascript:void(0);">广东省</a></li><li><a class="j a_sh_city" id="p-1400" href="javascript:void(0);">广西</a></li><li><a class="j a_sh_city" id="p-1000" href="javascript:void(0);">海南省</a></li><li><a class="j a_sh_city" id="p-1700" href="javascript:void(0);">河南省</a></li><li><a class="j a_sh_city" id="p-1800" href="javascript:void(0);">湖北省</a></li><li><a class="j a_sh_city" id="p-1900" href="javascript:void(0);">湖南省</a></li></ul></div><h3>西北-西南</h3><div class="optcon"><ul><li><a class="j a_sh_city" id="p-2000" href="javascript:void(0);">陕西省</a></li><li><a class="j a_sh_city" id="p-2700" href="javascript:void(0);">甘肃省</a></li><li><a class="j a_sh_city" id="p-3200" href="javascript:void(0);">青海省</a></li><li><a class="j a_sh_city" id="p-2900" href="javascript:void(0);">宁夏</a></li><li><a class="j a_sh_city" id="p-3100" href="javascript:void(0);">新疆</a></li><li><a class="j a_sh_city" id="p-0900" href="javascript:void(0);">四川省</a></li><li><a class="j a_sh_city" id="p-2600" href="javascript:void(0);">贵州省</a></li><li><a class="j a_sh_city" id="p-2500" href="javascript:void(0);">云南省</a></li><li><a class="j a_sh_city" id="p-3000" href="javascript:void(0);">西藏</a></li></ul></div><h3>其它</h3><div class="optcon"><ul><li><a class="j a_sh_city" id="p-3300" href="javascript:void(0);">香港</a></li><li><a class="j a_sh_city" id="p-3400" href="javascript:void(0);">澳门</a></li><li><a class="j a_sh_city" id="p-3500" href="javascript:void(0);">台湾</a></li></ul></div></div>
		</div>
	</div>
</div>
<div id="spop" style="top: 393px; left: 259px; display: none;"><ul><li><a href="javascript:void(0);" id="pc-1600" class="j a_sele_city">河北省</a></li><li><a href="javascript:void(0);" id="pc-1602" class="j a_sele_city">石家庄市</a></li><li><a href="javascript:void(0);" id="pc-1603" class="j a_sele_city">廊坊市</a></li><li><a href="javascript:void(0);" id="pc-1604" class="j a_sele_city seled">保定市</a></li><li><a href="javascript:void(0);" id="pc-1605" class="j a_sele_city">唐山市</a></li><li><a href="javascript:void(0);" id="pc-1606" class="j a_sele_city">秦皇岛市</a></li></ul></div>
<div id="overlay" style="height: 638px; display: none;"></div>